//
//  UIButton+Extension.swift
//  JLWeibo
//
//  Created by sunjinliang on 15/12/5.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

import UIKit
extension UIButton {
    
    convenience init(imageName: String, backImageName: String?){
        self.init()
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName+"_highlighted"), forState: .Highlighted)
        if backImageName != nil{
            
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            setBackgroundImage(UIImage(named: backImageName!+"_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
    }
    
    convenience init(title: String, backgroundImage: String, color: UIColor = UIColor.orangeColor()){
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(imageLiteral: backgroundImage), forState: .Normal)

    }
    convenience init(title: String, image: String? , color: UIColor = UIColor.orangeColor(),fontSize: CGFloat = 12){
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        if image != nil{
            
            setImage(UIImage(imageLiteral: image!), forState: .Normal)
        }
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
}